/* 
 * File:   MementoCaretaker.h
 * Author: Gab'z
 *
 * Created on 25 mai 2012, 17:53
 */

#ifndef MEMENTOCARETAKER_H
#define	MEMENTOCARETAKER_H

#include "Memento.h"
#include <list>
#include "../../exception/MementoException.h"
#include "../../log/LogSystem.h"

namespace calculator {

    class MementoCaretaker {
    public:
        void addMemento(const Memento* memento);

        static MementoCaretaker* getInstance() {
            if (instance == 0) instance = new MementoCaretaker();
            return instance;
        }

        static void deleteInstance() {
            if (instance != 0) delete instance;
        }

        unsigned int getCurrentMementoIndex() const;
        std::string getPreviousInputString() const;
        bool hasPrevious() const;
        bool hasNext() const;
        void goPrevious() throw (MementoException);
        void goNext() throw (MementoException);
        const Memento * getPreviousMemento() const throw (MementoException);
        const Memento * getNextMemento() const throw (MementoException);
    private:
        static MementoCaretaker* instance;
        void cutMementoList();
        std::list<const Memento*> _mementoList;
        std::list<const Memento*>::iterator _iteratorCurrentMemento;

        MementoCaretaker();
        //        MementoCaretaker(const MementoCaretaker & orig);
        virtual ~MementoCaretaker();
        static Logger* log;
    };
}
#endif	/* MEMENTOCARETAKER_H */

